package com.zzptc.tkfate;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    GridView gridView;//全局变量
    //int[] tupian=new int[10];
    int[] pics={R.mipmap.a1,R.mipmap.a2,R.mipmap.a3,R.mipmap.a4,R.mipmap.a5,R.mipmap.a6};

    String[] titles={"安卓","相机","视频","游戏","播放器","短信"};
    List<Map<String,Object>> list;

    //List<String> list1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gridView=findViewById(R.id.gv_menu);//实力化控件

        //第一步，布局（大 小）

        //第二步，准备数据
        list=new ArrayList<>();
        getData();

        /*Map<String,Object> map1=new HashMap<>();
        map.put("biaoti",titles[1]);
        map.put("icon",pics[1]);

        list.add(map);
        list.add(map1);*/
        String[] from={"biaoti","icon"};
        int[] to={R.id.tv_title,R.id.iv_pic};
        SimpleAdapter simpleAdapter=new SimpleAdapter(MainActivity.this,list,R.layout.item,from,to);
        gridView.setAdapter(simpleAdapter);
    }

    private void getData() {
        for (int i=0;i<titles.length;i++){
            Map<String,Object> map=new HashMap<>();
            map.put("biaoti",titles[i]);
            map.put("icon",pics[i]);
            //添加到集合里面
            list.add(map);
        }
    }
}
